package com.gitee.chili.leisure.service.impl;

import com.gitee.chili.leisure.domain.EntryRoom;
import com.gitee.chili.leisure.repository.EntryRoomRepository;
import com.gitee.chili.leisure.service.IEntryRoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * EntryRoomService
 *
 * @author week solider
 * @since 2020.09.04
 */
@Slf4j
@Service
public class EntryRoomService implements IEntryRoomService {

    @Autowired
    private EntryRoomRepository entryRoomRepository;

    @Override
    public EntryRoomRepository getRepository() {
        return entryRoomRepository;
    }


    @Override
    public Integer queryRoomMeanwhileGetPeopleNum(Long roomNum) {
        return entryRoomRepository.selectPeopleNum(roomNum, 1);
    }

    @Override
    public void leaveRoom(Long memberId) {
        entryRoomRepository.updateStatusByMemberId(memberId, 0);
    }

    @Override
    public List<EntryRoom> queryRoomMember(Long roomNum) {
        return entryRoomRepository.findByRoom_RoomNumAndStatus(roomNum, 1);
    }

    @Override
    public EntryRoom roomInside(Long memberId) {
        return entryRoomRepository.findByMember_IdAndStatus(memberId, 1);
    }
}
